package com.rd.student.jiaji.class4.suyan.zrrd.Read;
//1、将字符串"aaaaaaabbbbbcerrrrggggggggsssssspoqqqqq"
//        压缩处理成"a7b5cer4g8s6poq5"
public class Exercise2 {
    public static void main(String[] args) {
        String s1 = "aaaaaaabbbbbcerrrrggggggggsssssspoqqqqq";
        hanfleString1(s1);
        //handleString1(s1);
    }

    public static void hanfleString1(String s1) {
        String s2 = "" + s1.charAt(0);
        int count = 1;
        for (int i = 1; i < s1.length(); i++) {
            //比较的是 当前的字符和前一个字符是否相等
            //aaabbbcc
            //i=1和i=0比较是否相等 相等的话3count++
            //i=2和i=1比较
            //i=3和i=2比较
            //i=4和i=3比较
            if (s1.charAt(i) == s1.charAt(i - 1)) {
                count++;
            } else if (count != 1) {
                s2 = s2 + count + s1.charAt(i);
                count = 1;
            } else {
                s2 += s1.charAt(i);
            }
        }
        s2 += count;
        System.out.println(s2);

    }
}
